package com.thkj.modules.map.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thkj.camera.CamerasRequest;
import com.thkj.camera.HikCamerasResoures;
import com.thkj.modules.map.service.MapDetailsService;
import com.thkj.modules.dao.DevicesMapper;
import com.thkj.modules.user.entity.Device;
import com.thkj.modules.user.entity.TblCameraRele;
import com.thkj.modules.user.service.TblMoniConfigService;

import dp.service.BaseService;

@Service
public class MapDetailsServiceImpl extends BaseService implements MapDetailsService {

	@Autowired
	private DevicesMapper devicesMapper;

	@Autowired
	private TblMoniConfigService moniConfigService;

	@Override
	public Map<String, List<Object>> getDeviceCountAndType(String individual_id) {
		Map<String, List<Object>> mapItem = new HashMap<>();
		TblCameraRele cameraRele = moniConfigService.getByIndividualId(individual_id);
		if (cameraRele == null) {
			return mapItem;
		}
		List<Object> arrx = new ArrayList<>();
		List<Object> arry = new ArrayList<>();
		CamerasRequest camerasRequest = new CamerasRequest();
		camerasRequest.setPageNo(1);
		camerasRequest.setPageSize(200);
		camerasRequest.setRegionIndexCode(cameraRele.getIndexCode());
		camerasRequest.setTreeCode(cameraRele.getTreeCode());
		List<Map> cameras = HikCamerasResoures.getCameras(camerasRequest);
		Integer camersSize = 0;
		if (cameras != null) {
			camersSize = cameras.size();
		}
		arrx.add("摄像头");
		arrx.add("消毒柜");
		arrx.add("人脸识别+测温");

		Device device = new Device();
		device.setDeviceType(1);
		device.setIndividualId(individual_id);
		int sterilizerSize = devicesMapper.selectCount(device);
		device.setDeviceType(2);
		int faceDeviceSize = devicesMapper.selectCount(device);
		arry.add(camersSize);
		arry.add(sterilizerSize);
		arry.add(faceDeviceSize);

		mapItem.put("arrx", arrx);
		mapItem.put("arry", arry);
		return mapItem;
	}

	@Override
	public Map<String, List<Object>> querControlRatesStatistics(String individual_id, Integer type, String timeStr) {

		List<Object> arrx = new ArrayList<>();
		List<Object> arry = new ArrayList<>();
		if (type == 1) {
			for (int i = 1; i <= 12; i++) {
				arrx.add(i);
				if (i <= 4) {
					arry.add((int) (Math.random() * 21) + 80);
				} else {
					arry.add(0);
				}
			}
		} else if (type == 2) {
			int i1 = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
			for (int i = 1; i <= 30; i++) {
				arrx.add(i);
				if (i <= i1) {
					arry.add((int) (Math.random() * 21) + 80);
				} else {
					arry.add(0);
				}
			}
		} else if (type == 4) {
			String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
			Calendar cal = Calendar.getInstance();
			cal.setTime(new Date());
			int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
			for (int i = 0; i <= 6; i++) {
				arrx.add(weekDays[i]);
				if (w >= i) {
					arry.add((int) (Math.random() * 21) + 80);
				} else {
					arry.add(0);
				}
			}
		}

		Map<String, List<Object>> mapItem = new HashMap<>();
		mapItem.put("arrx", arrx);
		mapItem.put("arry", arry);
		return mapItem;
	}
}